import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_high_input_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_input_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_select_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/values/gaps.dart';

import 'controller.dart';

/// 添加/更新维护日志
class AddUpdateMaintainLogsPage extends StatelessWidget {
  AddUpdateMaintainLogsPage({super.key});

  final controller = Get.put(AddUpdateMaintainLogsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AddUpdateMaintainLogsController>(
        init: controller,
        builder: (controller) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: controller.maintenanceLogsEntity==null?'新增':'编辑',
            ),
            body: Container(
              color: const Color(0xFFF7FBFE),
              padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 14.w),
              child: ListView(
                children: [
                  CustomTitleChartPage(
                    title: '维护日志',
                    child: _tobWidget(),
                  ),
                  AppGaps.vGap30,
                ],
              ),
            ),
            bottomSheet: Container(
              width: double.infinity,
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  backgroundColor: AppColors.blue_button,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(22.r),
                  ),
                ),
                onPressed: controller.confirm,
                child: Text(
                  controller.maintenanceLogsEntity==null?'添加':'更新',
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: Colors.white,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ),
            ),
          );
        });
  }


  Widget _tobWidget() {
    return Column(
      children: [
        CustomInputPage(
          title: '操作人员：',
          isRequired: true,
          isEnabled: true,
          text: controller.maintainLogsRequestEntity.operators,
          hintText: '请输入',
          onCallBack: (value) {
            controller.maintainLogsRequestEntity.operators = value;
          },
        ),
        CustomSelectPage(
          isEnabled: true,
          isRequired: true,
          selectText: controller.maintainLogsRequestEntity.operationTime == ''
              ? ''
              : controller.maintainLogsRequestEntity.operationTime,
          title: '操作时间',
          hintText: '请选择',
          onCallBack: () {
            controller.showDatePicker();
          },
        ),
        CustomHighInputPage(
          isEnabled: true,
          title: '操作内容：',
          isRequired: true,
          text: controller.maintainLogsRequestEntity.maintenanceRecords,
          hintText: '请输入操作内容',
          onCallBack: (value) {
            controller.maintainLogsRequestEntity.maintenanceRecords = value;
          },
        ),
      ],
    );
  }
}
